(library (iter-utils)
  (export range)
  (import
    (except (rnrs base) let-values map error)
    (only (guile) lambda* λ)))


(define range
  (lambda* (start end #:key (end-inclusive #f) (start-inclusive #t) (step 1))
    (cond
     [(> start end) '()]
     [(= start end)
      (cond [end-inclusive (cons end '())]
            [else '()])]
     [else
      (cond [start-inclusive
             (cons start
                   (range (+ start step)
                          end
                          #:end-inclusive end-inclusive
                          #:step step))]
            [else
             (range (+ start step)
                    end
                    #:end-inclusive end-inclusive
                    #:start-inclusive #t  ; change after first element
                    #:step step)])])))
